package com.lagou.dao.impl;

import java.util.ArrayList;
import java.util.List;

import javax.sql.rowset.CachedRowSet;

import com.lagou.dao.ThirdDao;
import com.lagou.entity.Second;
import com.lagou.entity.Third;
import com.lagou.util.JDBCUtil2;

public class ThirdDaoImpl implements ThirdDao{
    JDBCUtil2 util=JDBCUtil2.getInit();

	@Override
	public Third queryByTid(int tid) {
		CachedRowSet rs=util.query("\r\n" + 
				"select t_third.sid,sname,tid,tname,t_third.fid from t_third ,t_second ,t_first where t_third.sid=t_second.sid and t_third.fid=t_first.fid and t_third.tid=?", tid);
		try{
			while(rs.next()) {
				Third t=new Third();
				t.setTid(rs.getInt("tid"));
				t.settName(rs.getString("tname"));
				t.setSid(rs.getInt("sid"));
				t.setFid(rs.getInt("fid"));
				return t;
			}
		}catch (Exception e) {
			e.printStackTrace();
		}finally {
			util.closeCacheRowSet(rs);
		}
		return null;
	}

	@Override
	public List<Integer> queryTid() {
		List<Integer> list = new ArrayList<Integer>();
		String sql="select tid from t_third";
		CachedRowSet rs=util.query(sql);
		try {
			while(rs.next()) {
				int a=new Integer(rs.getInt("tid"));
				list.add(a);
			}
			
		}  catch(Exception e) {
			e.printStackTrace();
		}finally {
			util.closeCacheRowSet(rs);
		}
		return list;
	}

//	@Override
//	public Third queryByFid(int fid) {
//		CachedRowSet rs=util.query("\r\n" + 
//				"select tname from t_first,t_second,t_third where t_first.fid=t_second.fid and t_second.sid=t_third.sid and t_first.fid=?", fid);
//		try{
//			while(rs.next()) {
//				Third t=new Third();
//				
//				t.settName(rs.getString("tname"));
//				
//				return t;
//				}
//			}catch(Exception e) {
//				e.printStackTrace();
//			}finally {
//				util.closeCacheRowSet(rs);
//			}
//		return null;
//	}	
	

}
